package cn.micai.base.io;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 描述：
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/6/20 14:36
 */
public class WriteFileExample {

    public static void main(String [] args) {
        FileOutputStream fileOutputStream = null;
        File file;
        String fileContent = "This is the next content";
        try {

            file = new File("D://newFile.txt");
            fileOutputStream = new FileOutputStream(file);

            if (!file.exists()) {
                file.createNewFile();
            }
            byte[] contentBytes = fileContent.getBytes();

            fileOutputStream.write(contentBytes);
            fileOutputStream.flush();
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
